package com.jiazhong.ssm.test06参数验证.config;

import com.jiazhong.ssm.test05拦截器.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @Auther:shuXin
 */
@EnableWebMvc
@Configuration
//手动扫描(SpringBoot之后就是自动扫描)
@ComponentScan({"com.jiazhong.ssm.test06参数验证"})
public class SpringMvcConfig implements WebMvcConfigurer {

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        //指定静态资源的地址
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    //开启静态资源的查找
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    /**
     * 添加的拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将拦截器添加到SpringMVC当中，默认拦截SpringMVC中的所有请求
        //registry.addInterceptor(new MyInterceptor());
        //将拦截器添加到SpringMVC当中，精确匹配
        //registry.addInterceptor(new MyInterceptor()).addPathPatterns("/user/*");
        //排除拦截器
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/user/*").excludePathPatterns("/user/get");
    }
}
